/**
 * 公用的main.js的引入内容
 *
 * 放在这里，其他页面的main.js引入此文件，就可以减少公用文件的引用，好维护
 *
 * @author yangjinlai 20200513
 */


import promise from 'es6-promise';

promise.polyfill();


//公用的splitUrl方法
import '@src/common/js/splitUrl.js';

//判断是ios手机
window.appIsIOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);

//iphoneX适配
(function(){
    function isIphoneX() {
        return /iphone/gi.test(navigator.userAgent) && (screen.height == 812 && screen.width == 375)
    }

    if (isIphoneX()) {
        document.getElementsByTagName('html')[0].style.maxHeight = document.body.clientHeight ;
        document.getElementsByTagName('body')[0].style.maxHeight = document.body.clientHeight ;
    }
})();


//750UI图适配
(function(doc, win) {
    var docEl = doc.documentElement,
        isIOS = navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
        dpr = isIOS ? Math.min(win.devicePixelRatio, 3) : 1,
        dpr = window.top === window.self ? dpr : 1, //被iframe引用时，禁止缩放
        dpr = 1,
        scale = 1 / dpr,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
    docEl.dataset.dpr = dpr;
    var metaEl = doc.createElement('meta');
    metaEl.name = 'viewport';
    metaEl.content = 'initial-scale=' + scale + ',maximum-scale=' + scale + ', minimum-scale=' + scale;
    docEl.firstElementChild.appendChild(metaEl);
    var recalc = function() {
        var width = docEl.clientWidth;
        if (width / dpr > 750) {
            width = 750 * dpr;
        }
        // 乘以100，px : rem = 100 : 1
        docEl.style.fontSize = 40 * (width / 750) + 'px';
    };
    recalc()
    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
})(document, window);


//公用的样式重置
import '@src/common/less/reset.less'

import '@config/project/root.js'

//字体不因屏幕大小而变化
import '@src/common/less/font-size.less'


//iconfont本地
import '@static/iconfont/iconfont.css';
import '@static/iconfont/iconfont.js'

//mint-ui
import MintUI from 'mint-ui'
import 'mint-ui/lib/style.css'

import axiosHttp from '@src/common/js/axios/axiosHttp.js'

//公用工具方法
import utils from '@src/common/js/utils'


//埋点文件
import '@src/common/md/lgbMd'

//黑条提示
import { Toast } from 'mint-ui';

//按钮
import { Button } from 'mint-ui';

export default function(Vue){

	Vue.use(MintUI)

    //ajax请求
	Vue.prototype.$axiosHttp = axiosHttp

    //工具方法
	Vue.prototype.$utils = utils

    //黑条提示
    Vue.prototype.$toast = Toast

    //按钮
    Vue.component(Button.name, Button);

}
